Detecting uninitialized memory references

ABSTRACT

A pre-initialized value of contents of a memory location is identified. A load value of contents loaded from the memory location by execution of a first instruction that loads from the memory location is also identified. A comparison is made between the load value and the pre-initialized value. Based on the comparison, a determination is made that the load value and the pre-initialized value are the same. In response to this determination, it is indicated that the first instruction contains an uninitialized memory reference.

BACKGROUND

The present disclosure relates to data processing and, morespecifically, to detecting uninitialized memory references.

Debugging is the process of finding problems, or “bugs,” during thedevelopment of a computer program. Most modern programming environmentsinclude a debugger that provides tools for testing and debugging acomputer program.

SUMMARY

According to embodiments of the present disclosure, aspects of thedisclosure may include a method, a system, and a computer programproduct for detecting an uninitialized memory reference. Apre-initialized value of contents of a memory location is identified. Aload value of contents loaded from the memory location by execution of afirst instruction that loads from the memory location is alsoidentified. A comparison is made between the load value and thepre-initialized value. Based on the comparison, a determination is madethat the load value and the pre-initialized value are the same. Inresponse to this determination, it is indicated that the firstinstruction contains an uninitialized memory reference.

The above summary is not intended to describe each illustratedembodiment or every implementation of the present disclosure.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

The drawings included in the present application are incorporated into,and form part of, the specification. They illustrate embodiments of thepresent disclosure and, along with the description, serve to explain theprinciples of the disclosure. The drawings are only illustrative of someembodiments and do not limit the disclosure.

FIG. 1 illustrates a flowchart of an example method for detectinguninitialized memory references, in accordance with embodiments of thepresent disclosure.

FIG. 2 illustrates a high-level flowchart of an example method forgenerating an uninitialized memory reference report for a specificprogram undergoing debug, in accordance with embodiments of the presentdisclosure.

FIG. 3 illustrates two tables that provide descriptions of machine codefor an example multi-threaded program undergoing debug, in accordancewith embodiments of the present disclosure.

FIG. 4 illustrates a flowchart of an example method for instrumentingmachine code during link time, in accordance with embodiments of thepresent disclosure.

FIG. 5 illustrates two tables that provide descriptions for instructionsof the example multi-threaded program referenced in FIG. 3 after theprogram has been instrumented, in accordance with embodiments of thepresent disclosure.

FIG. 6 illustrates a flowchart of an example method for generatingmemory access records during runtime, in accordance with embodiments ofthe present disclosure.

FIG. 7 illustrates a table that provides descriptions for the results ofexecuting the instrumented machine code of the example multi-threadedprogram referenced in FIG. 5, in accordance with embodiments of thepresent disclosure.

FIG. 8 illustrates a flowchart of an example method for delayed flaggingof uninitialized memory references, in accordance with embodiments ofthe present disclosure.

FIG. 9 illustrates a block diagram depicting two memory access tables,which are populated with the records created in reference to the examplemultithreaded program referenced in FIG. 7, being combined in order togenerate a combined records table, in accordance with embodiments of thepresent disclosure.

FIG. 10 illustrates a block diagram of the combined records table inFIG. 9 being analyzed in order to detect delayed uninitialized memoryreferences in the example multithreaded program code, in accordance withembodiments of the present disclosure.

FIG. 11 illustrates a high-level block diagram of an example computersystem that may be used in implementing one or more operations of themethods described herein, in accordance with embodiments of the presentdisclosure.

While the invention is amenable to various modifications and alternativeforms, specifics thereof have been shown by way of example in thedrawings and will be described in detail. It should be understood,however, that the intention is not to limit the invention to theparticular embodiments described. On the contrary, the intention is tocover all modifications, equivalents, and alternatives falling withinthe spirit and scope of the invention.

DETAILED DESCRIPTION

Aspects of the present disclosure relate to data processing and, morespecifically, to detecting uninitialized memory references. While thepresent disclosure is not necessarily limited to such applications,various aspects of the disclosure may be appreciated through adiscussion of various examples using this context.

A debugger or other tool may be configured to instrument a program atlink time so that the debugger can detect a variety of errors in theprogram during its execution. These errors may include, for example,uninitialized memory references (e.g., uninitialized variables), arraybounds exceeded, improper uses of allocated memory, and memory leaks. Inuse, the debugger may instrument the target program by inserting callsto specific types of instrumentation routines at specific points withinthe machine code of the target program. For example, a debugger mayinsert calls to a store-related instrumentation code before each storeinstruction in the target machine code. When invoked by a call, theseinstrumentation routines may create records that contain certainrelevant information related to one or more instructions of the targetmachine code. For example, in the case of the store-relatedinstrumentation code, each time it is called it may create a storerecord, described elsewhere herein, that includes information related tothe store instruction with which the call is associated (e.g., theinformation may include the memory location to which the storeinstruction stores).

In some situations, such a debugger may fail to detect certainuninitialized memory references due to timing window issues.Specifically, such a failure may occur in the context of a multithreadedprogram. For example, if a call to a store-related instrumentation codeis inserted before a related store instruction in a first thread, a loadinstruction in a second thread may ultimately be executed after the callbut before the store instruction. In this example, if the storeinstruction is the initializing instruction for a specific location andthe load instruction loads from that location, then the load instructioncan be said to contain an uninitialized memory reference (e.g., becauseit loads a pre-initialized value from the memory location). One problem,however, is that this uninitialized memory reference may not be detectedbecause the load instruction occurs after the call to the store-relatedinstrumentation code. More specifically, the debugger, relying on therecord created by the store-related instrumentation code, mayincorrectly presume that the store occurred before the load because thestore record was created before the load occurred (or, potentially,before an associated load record was created).

On a weakly consistent system, these timing window issues may be evenworse because the store instruction may drop significantly below itsassociated call to the store-related instrumentation code on theexecution path. Furthermore, the stored value may not show up on otherthreads until sometime later, yet updates to the instrumentation tablemay be visible sooner. In some situations, the instrumentation code thatupdates the table to mark the memory location as initialized may becoded such that the updates to the table are available to all of thethreads by the time the store instruction is actually executed. In someweakly consistent architectures, a sync instruction may be needed tobring the threads back into alignment. Thus, when the table is updatedin this manner, an uninitialized memory reference may be missed when itoccurs in another thread. In fact, in a weakly consistent system thesame storage location may be initialized in one thread and uninitializedin another.

One potential way to overcome this timing window issue might be toinsert the call to the store-related instrumentation code after (ratherthan before) the related store instruction. This potential solution,however, may have certain drawbacks. A first drawback is that creatingthe store record after executing the store instruction may create anopportunity for another thread to access the same memory location afterthe store instruction is executed but before the store record iscreated. This might result in a false positive error detection.Specifically, an uninitialized memory reference might be flagged when infact there was no uninitialized memory reference. Another drawback tocreating the store record after executing the store instruction is thatif the store instruction does cause an access violation it would not bedetected until afterward (e.g., until the store record is created). Athird drawback is that if the store-related instrumentation code is alsoconfigured to set a watch point (e.g., to monitor changes in variables),it may be more valuable to fire the watch point (e.g., execute theinstrumentation code) before the store occurs.

Referring now to FIG. 1, shown is a flowchart of an example method 100for detecting uninitialized memory references, in accordance withembodiments of the present disclosure. In some embodiments, one or moreoperations of this method may be performed by a debugger during debug ofa specific program. The debugger may run on a computer, such as computer1101 depicted in FIG. 11. Per operation 101, a pre-initialized value(e.g., uninitialized value) for the contents of a specific memorylocation is identified. This pre-initialized value may represent arandom value or other junk value of the contents of the memory locationprior to initialization of the memory location within the context of theprogram being debugged. Per operation 102, a load value of contents thatare loaded from the memory location by execution of a specificinstruction is identified. In some situations, operation 102 may happena significant amount of time before or after operation 101. In suchsituations, there may be a significant number of instructions that areexecuted and a significant number of values that are identified betweenoperations 101 and 102. Some of these instructions and values may relateto the specific memory location. Likewise, some of these instructionsand values may relate to other memory locations that are also beingmonitored.

Per operation 103, the load value is compared to the pre-initializedvalue. A determination is then made, per operation 104, as to whetherthe load value and the pre-initialized value are the same. If they arethe same, then, per operation 105, an indication is made (e.g., in thedebugging records) that the specific instruction contains anuninitialized memory reference. If, however, it is determined inoperation 105 that the load value and the pre-initialized value are notthe same, then no such indication is made.

Referring now to FIG. 2, shown is a high-level flowchart of an examplemethod 200 for generating an uninitialized memory reference report for aspecific program undergoing debug, in accordance with embodiments of thepresent disclosure. The method may begin at operation 201 with machinecode for the program undergoing debug being generated by compiling theprogram's source code. Per operation 202, the machine code is linked.During link time, per operation 203, the machine code is instrumented.In some embodiments, instrumenting may refer to inserting specific callsor other code segments that may be helpful for monitoring the programduring execution. Per operation 204, the instrumented machine code isexecuted. During runtime, per operation 205, uninitialized memoryreferences may be detected and flagged. Per operation 206, anuninitialized memory reference report may be generated based on theflagged uninitialized memory references. This report may be provided toa user.

In some embodiments, object code insertion may be used to hook a targetexecutable code in order to track loads (load records) and stores (storerecords) to and from one or more memory addresses. For each thread in amultithreaded target program, a list of the addresses and values thatare loaded and stored may be saved (e.g., in a memory access table). Forstores, values that existed in the stored location before (pre-storevalue) and after (store value) the store is performed may be recorded(e.g., in a store record), along with a time stamp indicating when therecord was created. The pre-store value may also be flagged or otherwisemarked when the location is uninitialized prior to the relevant store.

In some embodiments, the threads of the multithreaded program may beperiodically halted and their lists may be retrieved. The lists may thenbe combined (e.g., into a combined records table) based on time stamps,and a search may be undertaken in the combined records in order tolocate values in the records that are loaded from a given address butare not the most current value for that address (e.g., stale values).When a stale value is located and found to be flagged as uninitialized,a check is performed to determine if an uninitialized memory referencehad been issued previously for this memory address at this location(e.g. the relevant instruction in the program being debugged). If notthen a delayed uninitialized memory reference error detection notice maybe signaled for this location (e.g., recorded based on the address andline of the relevant instruction).

In some embodiments, a list of memory accesses (e.g. a memory accesstable) is maintained separately for each thread. In some embodiments,each list may be made up of entries (e.g., store records, load records),and each entry may contain a number of fields. By maintaining theselists for each thread, the values loaded and stored within that threadcan be accurately tracked. This may remain true even in weaklyconsistent systems, as weak consistency does not reorder loads andstores inside a single processor thread. Periodically, the program haltsand holds all the threads, combines the thread lists, checks for misseduninitialized memory references, and then cleans up or otherwise paresthe lists so that they do not grow unmanageably large.

In some embodiments, each load and store of the program being analyzedis instrumented using object code insertion technology. This may alloweach thread to gain control of each relevant load and store and allowthe debugger a chance to update its internal tables and detect errors.The debugger also updates the thread lists. Specifically, in someembodiments, before each load, an entry (e.g., load record) is createdin the thread list. The entry may contain, for example, the valueloaded, the memory address that the value is loaded from, the loadinstruction's address, and a timestamp indicating the time the entry iscreated. Similarly, before each store, an entry (e.g., a store record)is created in the thread list. This store record may contain, forexample, the pre-store value (e.g., the value at the location stored tobefore the store occurs) and an indication as to whether that pre-storevalue is pre-initialized (e.g., whether the location is uninitialized).If the address to be stored to is not yet initialized, then acorresponding uninitialized flag may be set. In some embodiments, asimilar check may also occur for load instructions in order to determinewhether the load value came from an initialized location.

Next, in some embodiments, after a specific amount of time has passed orafter a specific number of loads and stores have occurred, all of thethreads are halted. All of the thread lists are then combined into asingle list (e.g., a combined records table). This single list may beordered by time stamp. For each loaded value included in the combinedlist, a scan backwards through the list may be completed to make surethe loaded value matches the last value stored at the location fromwhich the load value was loaded. If the load value does not match thatstored value, then the pre-store value associated with that stored valuemay also be checked to see if it matches the load value. If the loadvalue does match the pre-store value and the pre-initialized valueindicator is set for that pre-store value, then it may be concluded thatthe instruction that caused the load value to be loaded contained anuninitialized memory reference. A check is then made to see if theuninitialized memory reference for that instruction had been alreadybeen flagged. If it was not previously flagged, then a delayeduninitialized memory reference flag is set for the instruction.

In some embodiments, in order to prevent the combined records table fromgrowing unmanageably large, it may be pruned from time to time. Forexample, during the halt in which the search for missed uninitializedmemory references is undertaken, old store records and load records maybe removed from the table. The individual thread lists may also becleared. Then, during the next halt, the pruned list may be combinedwith the new combined records table and the process may be repeated.

Referring now to FIG. 3, shown are two tables 301 and 302 that providedescriptions of machine code for an example multi-threaded programundergoing debug, in accordance with embodiments of the presentdisclosure. In this example, the multi-threaded program includes a firstthread (thread A) with instructions that are described in table 301 andsecond thread (thread B) with instructions that are described in table302. As shown in table 301, thread A includes two instructions ofinterest interspersed among other various instructions. The first ofthese two instructions is “STA20 11” which is an instruction (e.g., astore instruction) to store a value of 20 to the memory location havingthe memory address of 11. The second of these two instructions is “STA3012” which is an instruction to store a value of 30 to the memorylocation having the memory address of 12.

As shown in table 302, thread B also includes two instructions ofinterest interspersed among various other instructions. Specifically,thread B includes an instruction “LDA 11” which is an instruction (e.g.,a load instruction) to load a value from the memory location having thememory address 11. Thread B also includes an instruction “LDA 12” whichis an instruction to load a value from the memory location having amemory address of 12.

Referring now to FIG. 4, shown is a flowchart of an example method 400for instrumenting machine code during link time, in accordance withembodiments of the present disclosure. In some embodiments, one or moreoperations of method 400 may correspond to operation 203 of FIG. 2.Method 400 may begin at operation 401 with the beginning of linking themachine code. Per operation 402, a first instruction in the machine codeto be instrumented is identified. Per operation 403, the targetinstruction (in this instance, the first instruction) is analyzed. Peroperation 404, a determination is made as to whether the targetinstruction is a store instruction. If the target instruction is a storeinstruction then, per operation 405, a call to store-relatedinstrumentation code is inserted before the target instruction. In someembodiments, this may be a call to a routine, subroutine, or separatedebugging program.

If a determination is made in operation 404 that the target instructionis not a store instruction, then per operation 406, a determination ismade as to whether the target instruction is a load instruction. If thetarget instruction is a load instruction, then, per operation 407, acall to a load-related instrumentation code is inserted before thetarget instruction. In some embodiments, this may be a call to aroutine, subroutine, or program that is the same as or different fromthe one used for store instructions.

Once the required instrumentation (if any) of the first instruction iscompleted, then a determination is made per operation 408 as to whetherthere are any remaining instructions in the machine code to beinstrumented. For each remaining instruction in the machine code, theinstruction is analyzed, per operation 403, and properly instrumented,per operations 403-407. Once all of the instructions have been analyzedand instrumented as applicable, the linking of the machine code isfinished, per operation 409.

Referring now to FIG. 5, shown are two tables 501 and 502 that providedescriptions of instructions of the example multi-threaded programreferenced in FIG. 3 after the program has been instrumented, inaccordance with embodiments of the present disclosure. The program mayhave been instrumented, for example, using method 400 of FIG. 4. Asshown in table 501, two call instructions have been inserted in thread Aof the program. Specifically, inserted immediately before the “STA20 11”instruction is an instruction of “CALL instrumentation_for_store (STA2011).” This instruction is a call to the store-related instrumentationcode in order to create a store record for the next store instruction(e.g., STA20 11). Another instruction of “CALL instrumentation_for_store(STA30 12)” is inserted before the “STA30 12” instruction. Thisinstruction is also a call to the store-related instrumentation code andis used to create a store record for the next store instruction (e.g.,STA30 12).

As shown in table 502, two call instructions have also been inserted inthread B of the program. Specifically, inserted immediately before the“LDA 11” instruction is an instruction of “CALL instrumentation_for_load(LDA 11).” This instruction is a call to the load-relatedinstrumentation code in order to create a load record for the loadinstruction “LDA 11”. Another instruction of “CALLinstrumentation_for_load (LDA 12)” is inserted before the “LDA 12”instruction. This instruction is also a call to the load-relatedinstrumentation code and is used to create a load record for the loadinstruction “LDA 12.”

Referring now to FIG. 6, shown is a flowchart of an example method 600for generating memory access records during runtime, in accordance withembodiments of the present disclosure. In some embodiments, one or moreoperations of method 600 may correspond to operation 205 of FIG. 2.Method 600 may start at operation 601 with beginning execution of aninstrumented machine code. In some embodiments, the machine code mayhave been instrumented using, for example, one or more operations ofmethod 400 of FIG. 4.

Per operation 602, a first call to instrumentation code is identified.Per operation 603, a determination is made as to whether the call is tostore-related instrumentation code. If the call is to store-relatedinstrumentation code, then, per operation 604 a store record isgenerated in the memory access table for the appropriate thread (e.g.,the thread containing the relevant call instruction). In someembodiments, a memory access table may include specific informationabout all of the memory accesses for that thread within a given timeperiod. Furthermore, a store record may refer to an entry in the memoryaccess table that provides specific information about a specific storeinstruction. Per operation 605, several pieces of information may berecorded in the store record including, without limitation, a memoryblock address of the memory location to which the store instructionstores, a pre-store value of the contents of that memory location beforethe store occurs, an indication as to whether the memory location wasinitialized prior to the store (e.g., whether the pre-store value is apre-initialized value), a store value of the contents stored at thememory location by the store instruction, a time stamp indicating thetime that the store record is created, and an address (or otheridentifier) of the store instruction. In some embodiments, a storerecord may include any number of categories or fields of information(e.g., a store record may include only the memory block address of therelevant memory location and nothing more).

If, per operation 603, a determination is made that the first call toinstrumentation code is not a call to store-related instrumentationcode, then, per operation 606, a determination is made as to whether thefirst call to instrumentation code is a call to load-relatedinstrumentation code. If the call is to the load-related instrumentationcode, then, per operation 607, a load record is generated in the memoryaccess table for the appropriate thread. Per operation 608, severalpieces of information may be recorded in the load record including,without limitation, a memory block address of the memory location fromwhich the load instruction loads, the load value of the contents loadedfrom that memory location by the load instruction, a time stampindicating the time that the load record is created, and an address (orother identifier) of the load instruction. In some embodiments, a loadrecord may include any number of categories of information. Peroperation 609, a determination is made as to whether the memory blockfrom which the target load instruction loads is recognized asuninitialized. If so, then, per operation 610, the target loadinstruction is flagged (e.g., marked, indicated) as having anuninitialized memory reference.

In some embodiments, by performing operations 609 and 610 for each callto load-related instrumentation code within the instrumented machinecode, a debugger may identify and flag some (or even most) situationswhere uninitialized memory references occur. In other words, in someembodiments, some uninitialized memory references may be identifiedprior to the load records being compared to store records (e.g., asdescribed in method 800 of FIG. 8).

Once the appropriate determinations of operations 603 and 606 have beencompleted for the first call to instrumentation code, and theappropriate store record or load record (if applicable) has beencreated, then, per operation 611, an instrumentation code call counteris updated to reflect that the first call has been encountered. In someembodiments, this counter may serve to count each time a call toinstrumentation code occurs or each time a memory access record iscreated. Per operation 612, a determination is made as to whether acounter threshold has been achieved. This threshold may include, forexample, a specific number of memory access records having been createdor a specific amount of time having passed since the last halt of all ofthe threads. If a determination is made that the counter has achievedthe threshold, then control passes to operation 801 of FIG. 8. If,however, the threshold is not achieved, or after operation 817 of FIG. 8has been completed, then, per operation 613, a determination is made asto whether there are additional calls to instrumentation code within theinstrumented machine code. If there are additional calls, thenoperations 603-612 are repeated, as applicable, for each call. Once allof the calls to instrumentation code have been encountered and analyzedin this manner, then the execution of the instrumented machine code iscompleted, per operation 614.

Referring now to FIG. 7, shown is a table 700 that provides descriptionsof the results of executing the instrumented machine code of the examplemulti-threaded program referenced in FIG. 5, in accordance withembodiments of the present disclosure. The program may have beenexecuted, for example, using method 600 of FIG. 6. As shown in the table700, the significant portion of the example program has been executedand several records have been created. Specifically, beginning at timeone and continuing through time fifteen, various instructions areexecuted and various actions, including, for example, loads and storesoccur in one or both of thread A and thread B of the examplemultithreaded program. At time sixteen, the instruction of “CALLinstrumentation_for_store (STA20 11)” is executed in thread A. As aresult of the call, a store record is created in thread A's memoryaccess table. The store record indicates that the memory location towhich the value is stored has an address of 11, that the pre-store valueat that location is 10, that the value stored is 20, that the time ofthis occurrence is 16, and that the pre-store value at that location ispre-initialized (e.g., the memory location is uninitialized prior to thestore).

Continuing through table 700, at time seventeen the execution of theexample program switches from thread A to thread B. From time seventeenthrough twenty-five, various instructions are executed in thread B. Attime twenty-six, the instruction of “CALL instrumentation_for_load (LDA11)” is executed in thread B. As a result of the call, a load record iscreated in thread B's memory access table. The load record indicatesthat the memory location from which the value is loaded has an addressof 11, that the value loaded is 10, and that the time of this occurrenceis 26. Next, at time twenty-seven, the instruction “LDA 11” is executedin thread B and a pre-initialized value of 10 is loaded from thelocation having memory address 11. Then from time twenty-eight throughforty, various instructions are executed in thread B. At time forty-one,the execution of the example program switches back to thread A, and theinstruction “STA20 11” is executed. This causes a value of 20 to bestored in the location having memory address 11. Next, between timeforty-two and fifty-five, various instructions are executed in one orboth threads.

At time fifty-six, another call instruction of interest, “CALLinstrumentation_for_store (STA30 12),” is executed in thread A. As aresult of this call, another store record is created in thread A'smemory access table. This store record indicates that the memorylocation to which the relevant value is stored has an address of 12,that the pre-store value at that location is 40, that the value storedis 30, that the time of this occurrence is 56, and that the pre-storevalue at that location is pre-initialized. Next, at time fifty-seven,the instruction “STA30 12” is executed and a value of 30 is stored inthe location having memory address 12. Between times fifty-eight andsixty-five, various instructions are executed in one or both of thethreads. At time sixty-six, another load-related call instruction, “CALLinstrumentation_for_load (LDA 12),” is executed in thread B. As a resultof the call, another load record is created in thread B's memory accesstable. The load record indicates that the memory location from which thevalue is loaded has an address of 12, that the value loaded is 30, andthat the time of this occurrence is 66. Next, at time sixty-seven, theload instruction “LDA 12” is executed in thread B and an initializedvalue of 30 is loaded from the location having memory address 12.Finally, from time sixty-eight to time eighty, various instructions areexecuted in one or both threads.

It is noted that the table 700 provides at least one example of how anuninitialized memory reference (of a type that some embodiments of thepresent disclosure may be configured to detect) can occur duringexecution of a multithreaded program. Specifically, the load instruction“LDA 11” loads from memory address 11 prior to the initialization ofthat location by execution of the store instruction “STA20 11” but afterthe store record for that instruction has been created in response tothe instruction of “Call instrumentation_for_store (STA20 11).” On theother hand, an example of a proper load (e.g., a load that is without anuninitialized memory reference) is also provided. Specifically, the loadinstruction “LDA 12” loads from memory address 12 after theinitialization of that location by the store instruction “STA30 12.”

Referring now to FIG. 8, shown is a flowchart of an example method 800for delayed flagging of uninitialized memory references, in accordancewith embodiments of the present disclosure. In some embodiments, one ormore operations of method 800 may correspond to operation 205 of FIG. 2.Method 800 may start at operation 801 after a counter threshold has beenachieved (per operation 612 of FIG. 6). Per operation 801, the executionof the instrumented machine code is halted. Per operation 802, thememory access tables of all threads of the multithreaded program arecombined. If there is a pruned records table (described elsewhereherein) then the pruned records table is combined as well. Per operation803, a combined records table is generated by ordering the combinedmemory access records by timestamps (e.g., oldest to newest or newest tooldest).

Once the combined records table is generated, then, per operation 804,the most recent (e.g., most recently created) load record is identified,for example, by finding the load record listed closest to the top of thecombined records table. Per operation 805, the memory block addressindicated in this target load record is identified. A scan backward isthen completed, per operation 806, in order to identify the mostrecently created store record that both was created prior to the targetload record and includes a memory address that matches the target loadrecord memory address.

Once this target store record is identified, then, per operation 807,the target load record and target store record are compared. Based onthis comparison, at least three determinations may be made.Specifically, per operation 808, a first determination is made as towhether the listed load value of the target load record matches thelisted store value of the target store record. If so, then the methodcontinues to operation 813. If, however, a determination is made thatthe store value and load value do not match, then, per operation 809, asecond determination is made as to whether the listed load value matchesthe pre-store value listed in the target store record. If not, then themethod continues to operation 813. If the load value does match thepre-store value, however, then, per operation, a third determination ismade as to whether the listed pre-store value is indicated (e.g.,marked) as pre-initialized in the target store record. If the pre-storevalue is not marked as pre-initialized, then the method continues tooperation 813. If, however, the pre-store value is marked as apre-initialized value, then, as a result of the three determinations ofoperations 808-810, the target load instruction may be deemed ascontaining an uninitialized memory reference.

Continuing to operation 811, after the uninitialized memory reference isidentified, a check is made as to whether that uninitialized memoryreference had been flagged previously. If not, then, per operation 812,a delayed flag is set to indicate that the target load instructioncontains an uninitialized memory reference. After the flag is set (orafter the determination is made in operation 811 that the flag waspreviously set), then the method 800 continues to operation 813.

In operation 813, a determination is made as to whether there are anyremaining load records to be analyzed in the combined records table. Ifso, then for each additional load record operations 805-812 are repeated(as applicable). Once all of the load records of the combined recordstable have been reviewed in this manner, then a pruned records table isgenerated from the combined records table, per operation 814. In someembodiments, this is completed by deleting all memory access records(both store records and load records) in the combined records tableexcept the most recently created store record for each memory blockaccessed. This pruned records table may then be utilized in a futureiteration of method 800.

Per operation 815, the memory access tables for each thread are thencleared as well. Per operation 816, the instrumentation code callcounter (referenced in operation 611 of FIG. 6) is reset (e.g., to acount of zero). Finally, per operation 817, the execution of theinstrumented machine code is resumed and control is returned tooperation 613 of FIG. 6.

While an example of an embodiment of method 800 is provided herein, itis contemplated that, in some embodiments, many other variants on method800 are possible. For example, in some embodiments, if, in operation809, a determination is made that the load value does not match thepre-store value, then a second most recent store record created prior tothe target load record that is associated with the same memory blocklocation may be identified. The store value and then the pre-store valuefrom that second store record may be compared to the load value from theload record. This process may then be repeated continuing backwardthrough the store records of the combined records table until a matchfor the load value is found in a store record. Using these additionaloperations, it may be possible to trace back through the records inorder to identify which store instruction was actually the initializinginstruction for that location and also to determine whether thepre-initialized value for that location matches the load value.

Referring now to FIG. 9, shown is a block diagram depicting two memoryaccess tables 901 and 902 (which are populated with the records createdin reference to the example multithreaded program referenced in FIG. 7)being combined in order to generate a combined records table 903, inaccordance with embodiments of the present disclosure. This combinationmay occur, for example, using operations 801-803 of FIG. 8. As shown,the thread A memory access table 901 lists the relevant thread A memoryaccess records, including the store record for the instruction “STA2011” which was generated by executing the call instruction “CALLinstrumentation_for_store (STA20 11)” and also including the storerecord for the instruction “STA30 12” which was generated by executingthe call instruction “CALL instrumentation_for_store (STA30 12).” Alsoshown is the thread B memory access table 902. This memory access table902 lists the relevant thread B memory access records, including theload record for the instruction “LDA 11” which was generated byexecuting the call instruction “CALL instrumentation_for_load (LDA 11)”and the load record for the instruction “LDA 12” which was generated byexecuting the call instruction “CALL instrumentation_for_load (LDA 12)”.

As shown, the memory access tables 901 and 902 are joined to create acombined records table 903. In this example, the combined records table903 has the memory access records separated into groups based on memoryaddress and sorted within these groups based on time stamp.Specifically, the store record for “STA20 11” is grouped with the loadrecord for “LDA 11” as well as any other records that pertain to thememory location having memory address 11. Similarly, the store recordfor “STA30 12” is grouped with the load record for “LDA 12” as well asany other records that pertain to the memory location having memoryaddress 12.

Referring now to FIG. 10, shown is a block diagram of the combinedrecords table 903 of FIG. 9 being analyzed in order to detect delayeduninitialized memory references in the example multithreaded programcode, in accordance with embodiments of the present disclosure. Thisanalysis may occur, for example, using multiple iterations of operations805-812 of FIG. 8. As shown, the memory access records for memoryaddress 11 may be used to determine whether the load instruction “LDA11” should be flagged as containing an uninitialized memory reference.Specifically, the load record for “LDA 11” (created at time twenty-six)is compared with the most recent store record that was created beforethe load record and references the same memory address. In this instancethe store record of interest is for “STA20 11” (created at timesixteen). Once identified, the load value in the load record is comparedwith the store value in the store record. In this instance, this loadvalue 10 is not the same as the store value of 20. Next, the load valueis compared with the pre-store value. Here, because the load value andpre-store value are both 10 and because the pre-store value is flaggedas pre-initialized in the store record, the load instruction “LDA 11” isflagged as having an uninitialized memory reference.

Also as shown in FIG. 10, a similar analysis may be carried out relatingto the load instruction “LDA 12.” Specifically, the load record for “LDA12” (created at time sixty-six) is compared with the most recent storerecord that was created before the load record and references the memoryaddress 12. Here, the identified store record is for “STA20 11” (createdat time fifty). Once identified, the load value in the load record (30)is compared with the store value in the store record (also 30). In thisinstance, the load value and the store value match, and the loadinstruction “LDA 12” is, therefore, not flagged as having anuninitialized memory reference.

Referring now to FIG. 11, shown is a high-level block diagram of anexample computer system (i.e., computer) 1101 that may be used inimplementing one or more of the methods, tools, and modules, and anyrelated functions or operations, described herein (e.g., using one ormore processor circuits or computer processors of the computer), inaccordance with embodiments of the present disclosure. In someembodiments, the major components of the computer system 1101 maycomprise one or more CPUs 1102, a memory subsystem 1104, a terminalinterface 1112, a storage interface 1114, an I/O (Input/Output) deviceinterface 1116, and a network interface 1118, all of which may becommunicatively coupled, directly or indirectly, for inter-componentcommunication via a memory bus 1103, an I/O bus 1108, and an I/O businterface unit 1110.

The computer system 1101 may contain one or more general-purposeprogrammable central processing units (CPUs) 1102A, 1102B, 1102C, and1102D, herein generically referred to as the CPU 1102. In someembodiments, the computer system 1101 may contain multiple processorstypical of a relatively large system; however, in other embodiments thecomputer system 1101 may alternatively be a single CPU system. Each CPU1102 may execute instructions stored in the memory subsystem 1104 andmay comprise one or more levels of on-board cache.

In some embodiments, the memory subsystem 1104 may comprise arandom-access semiconductor memory, storage device, or storage medium(either volatile or non-volatile) for storing data and programs. In someembodiments, the memory subsystem 1104 may represent the entire virtualmemory of the computer system 1101, and may also include the virtualmemory of other computer systems coupled to the computer system 1101 orconnected via a network. The memory subsystem 1104 may be conceptually asingle monolithic entity, but, in some embodiments, the memory subsystem1104 may be a more complex arrangement, such as a hierarchy of cachesand other memory devices. For example, memory may exist in multiplelevels of caches, and these caches may be further divided by function,so that one cache holds instructions while another holds non-instructiondata, which is used by the processor or processors. Memory may befurther distributed and associated with different CPUs or sets of CPUs,as is known in any of various so-called non-uniform memory access (NUMA)computer architectures.

In some embodiments, the main memory or memory subsystem 1104 maycontain elements for control and flow of memory used by the CPU 1102.This may include all or a portion of the following: a memory controller1105, one or more memory buffers 1106A and 1106B and one or more memorydevices 1125A and 1125B. In some embodiments, the memory devices 1125Aand 1125B may be dual in-line memory modules (DIMMs), which are a seriesof dynamic random-access memory (DRAM) chips 1107A-1107D (collectivelyreferred to as 1107) mounted on a printed circuit board and designed foruse in personal computers, workstations, and servers. The use of DRAMs1107 in the illustration is exemplary only and the memory array used mayvary in type as previously mentioned.

Although the memory bus 1103 is shown in FIG. 11 as a single busstructure providing a direct communication path among the CPUs 1102, thememory subsystem 1104, and the I/O bus interface 1110, the memory bus1103 may, in some embodiments, comprise multiple different buses orcommunication paths, which may be arranged in any of various forms, suchas point-to-point links in hierarchical, star or web configurations,multiple hierarchical buses, parallel and redundant paths, or any otherappropriate type of configuration. Furthermore, while the I/O businterface 1110 and the I/O bus 1108 are shown as single respectiveunits, the computer system 1101 may, in some embodiments, containmultiple I/O bus interface units 1110, multiple I/O buses 1108, or both.Further, while multiple I/O interface units are shown, which separatethe I/O bus 1108 from various communications paths running to thevarious I/O devices, in other embodiments some or all of the I/O devicesmay be connected directly to one or more system I/O buses.

In some embodiments, the computer system 1101 may be a multi-usermainframe computer system, a single-user system, or a server computer orsimilar device that has little or no direct user interface, but receivesrequests from other computer systems (clients). Further, in someembodiments, the computer system 1101 may be implemented as a desktopcomputer, portable computer, laptop or notebook computer, tabletcomputer, pocket computer, telephone, smart phone, network switches orrouters, or any other appropriate type of electronic device.

It is noted that FIG. 11 is intended to depict the representative majorcomponents of an exemplary computer system 1101. In some embodiments,however, individual components may have greater or lesser complexitythan as represented in FIG. 11, components other than or in addition tothose shown in FIG. 11 may be present, and the number, type, andconfiguration of such components may vary.

As discussed in more detail below, it is contemplated that some or allof the operations of some of the embodiments of methods described hereinmay be performed in alternative orders or may not be performed at all;furthermore, multiple operations may occur at the same time or as aninternal part of a larger process.

The present invention may be a system, a method, and/or a computerprogram product. The computer program product may include a computerreadable storage medium (or media) having computer readable programinstructions thereon for causing a processor to carry out aspects of thepresent invention.

The computer readable storage medium can be a tangible device that canretain and store instructions for use by an instruction executiondevice. The computer readable storage medium may be, for example, but isnot limited to, an electronic storage device, a magnetic storage device,an optical storage device, an electromagnetic storage device, asemiconductor storage device, or any suitable combination of theforegoing. A non-exhaustive list of more specific examples of thecomputer readable storage medium includes the following: a portablecomputer diskette, a hard disk, a random access memory (RAM), aread-only memory (ROM), an erasable programmable read-only memory (EPROMor Flash memory), a static random access memory (SRAM), a portablecompact disc read-only memory (CD-ROM), a digital versatile disk (DVD),a memory stick, a floppy disk, a mechanically encoded device such aspunch-cards or raised structures in a groove having instructionsrecorded thereon, and any suitable combination of the foregoing. Acomputer readable storage medium, as used herein, is not to be construedas being transitory signals per se, such as radio waves or other freelypropagating electromagnetic waves, electromagnetic waves propagatingthrough a waveguide or other transmission media (e.g., light pulsespassing through a fiber-optic cable), or electrical signals transmittedthrough a wire.

Computer readable program instructions described herein can bedownloaded to respective computing/processing devices from a computerreadable storage medium or to an external computer or external storagedevice via a network, for example, the Internet, a local area network, awide area network and/or a wireless network. The network may comprisecopper transmission cables, optical transmission fibers, wirelesstransmission, routers, firewalls, switches, gateway computers and/oredge servers. A network adapter card or network interface in eachcomputing/processing device receives computer readable programinstructions from the network and forwards the computer readable programinstructions for storage in a computer readable storage medium withinthe respective computing/processing device.

Computer readable program instructions for carrying out operations ofthe present invention may be assembler instructions,instruction-set-architecture (ISA) instructions, machine instructions,machine dependent instructions, microcode, firmware instructions,state-setting data, or either source code or object code written in anycombination of one or more programming languages, including an objectoriented programming language such as Smalltalk, C++ or the like, andconventional procedural programming languages, such as the “C”programming language or similar programming languages. The computerreadable program instructions may execute entirely on the user'scomputer, partly on the user's computer, as a stand-alone softwarepackage, partly on the user's computer and partly on a remote computeror entirely on the remote computer or server. In the latter scenario,the remote computer may be connected to the user's computer through anytype of network, including a local area network (LAN) or a wide areanetwork (WAN), or the connection may be made to an external computer(for example, through the Internet using an Internet Service Provider).In some embodiments, electronic circuitry including, for example,programmable logic circuitry, field-programmable gate arrays (FPGA), orprogrammable logic arrays (PLA) may execute the computer readableprogram instructions by utilizing state information of the computerreadable program instructions to personalize the electronic circuitry,in order to perform aspects of the present invention.

Aspects of the present invention are described herein with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems), and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer readable program instructions.

These computer readable program instructions may be provided to aprocessor of a general purpose computer, special purpose computer, orother programmable data processing apparatus to produce a machine, suchthat the instructions, which execute via the processor of the computeror other programmable data processing apparatus, create means forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks. These computer readable program instructionsmay also be stored in a computer readable storage medium that can directa computer, a programmable data processing apparatus, and/or otherdevices to function in a particular manner, such that the computerreadable storage medium having instructions stored therein comprises anarticle of manufacture including instructions which implement aspects ofthe function/act specified in the flowchart and/or block diagram blockor blocks.

The computer readable program instructions may also be loaded onto acomputer, other programmable data processing apparatus, or other deviceto cause a series of operational steps to be performed on the computer,other programmable apparatus or other device to produce a computerimplemented process, such that the instructions which execute on thecomputer, other programmable apparatus, or other device implement thefunctions/acts specified in the flowchart and/or block diagram block orblocks.

The flowchart and block diagrams in the Figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof instructions, which comprises one or more executable instructions forimplementing the specified logical function(s). In some alternativeimplementations, the functions noted in the block may occur out of theorder noted in the figures. For example, two blocks shown in successionmay, in fact, be executed substantially concurrently, or the blocks maysometimes be executed in the reverse order, depending upon thefunctionality involved. It will also be noted that each block of theblock diagrams and/or flowchart illustration, and combinations of blocksin the block diagrams and/or flowchart illustration, can be implementedby special purpose hardware-based systems that perform the specifiedfunctions or acts or carry out combinations of special purpose hardwareand computer instructions.

The descriptions of the various embodiments of the present disclosurehave been presented for purposes of illustration, but are not intendedto be exhaustive or limited to the embodiments disclosed. Manymodifications and variations will be apparent to those of ordinary skillin the art without departing from the scope and spirit of the describedembodiments. The terminology used herein was chosen to best explain theprinciples of the embodiments, the practical application or technicalimprovement over technologies found in the marketplace, or to enableothers of ordinary skill in the art to understand the embodimentsdisclosed herein.

What is claimed is:
 1. A system for detecting an uninitialized memoryreference, the system comprising: a memory; at least one processorcircuit in communication with the memory, wherein the at least oneprocessor circuit is configured to perform a method comprising:identifying a pre-initialized value of contents of a memory location;identifying a load value of contents loaded from the memory location byexecution of a first instruction that loads from the memory location;comparing the load value to the pre-initialized value; determining,based on the comparing, that the load value and the pre-initializedvalue are the same; and indicating, in response to the determining, thatthe first instruction contains the uninitialized memory reference. 2.The system of claim 1, wherein the identifying the pre-initialized valueof contents of the memory location comprises: creating, for a secondinstruction that stores to the memory location, a second record thatincludes a pre-store value of contents of the memory location prior toexecution of the second instruction, wherein the pre-store value is thepre-initialized value.
 3. The system of claim 2, wherein the pre-storevalue is not a known value prior to beginning debugging of the programcontaining the uninitialized memory reference.
 4. The system of claim 2,wherein the pre-initialized value is a junk value.
 5. The system ofclaim 2, wherein the identifying the load value of contents loaded fromthe memory location by execution of the first instruction that loadsfrom the memory location comprises: creating, for the first instruction,a first record that includes the load value.
 6. The system of claim 5,wherein the comparing the load value to the pre-initialized valuecomprises: comparing the load value from the first record to thepre-store value from the second record.
 7. The system of claim 6,wherein the second record further includes an indicator that the memorylocation is uninitialized prior to execution of the second instruction.8. The system of claim 7, wherein the method further comprises:identifying the indicator in the second record, wherein the indicatingthat the first instruction contains the uninitialized memory referenceis further in response to the identifying the indicator in the secondrecord.
 9. The system of claim 6, wherein the method further comprises:executing, subsequent to the creating the second record and prior toexecuting the second instruction, the first instruction, whereby thefirst instruction causes the pre-store value to be loaded from thememory location.
 10. The system of claim 6, wherein the firstinstruction is in a first thread of a multi-threaded program, andwherein the second instruction is in a second thread of themulti-threaded program.
 11. The system of claim 10, wherein the methodfurther comprises: generating machine code for the multi-threadedprogram by compiling source code for the multi-threaded program; andinstrumenting the machine code, wherein the instrumenting includes,inserting, before the first instruction, a first call to a firstinstrumentation code configured to cause the creating the first record,and wherein the instrumenting further includes inserting, before thesecond instruction, a second call to a second instrumentation codeconfigured to cause the creating the second record.
 12. The system ofclaim 7, wherein the first record further includes a first timestampconfigured to indicate that the creating the first record occurred at afirst time, wherein the second record further includes a secondtimestamp configured to indicate that the creating the second recordoccurred at a second time, wherein the second time occurs prior to thefirst time, and wherein the method further comprises: executing,subsequent to the creating the second record and the creating the firstrecord, the first instruction; and executing, subsequent to theexecuting the first instruction, the second instruction.
 13. The systemof claim 10, wherein the first instruction is a load instruction,wherein the second instruction is a store instruction, wherein the firstrecord is a load record, wherein the second record is a store record,and wherein the method further comprises: beginning an execution of themulti-threaded program; generating, during the execution of themulti-threaded program and for the first thread, a first memory accesstable including a first plurality of load records and further includinga first plurality of store records, the first plurality of load recordsincluding the load record; generating, during the execution of themulti-threaded program and for the second thread, a second memory accesstable including a second plurality of load records and further includinga second plurality of store records, the second plurality of storerecords including the store record; halting the execution of themulti-threaded program; combining, during the halt, the first memoryaccess table and the second memory access table; sorting, during thehalt and based on time of creation and further based on memory location,the records of the combined table; and resuming, subsequent to the halt,the execution of the multi-threaded program, wherein the comparing theload value from the load record to the pre-store value from the storerecord and the indicating that the load instruction contains theuninitialized memory reference both occur during the halt.
 14. Thesystem of claim 10, wherein the first instruction is a load instruction,wherein the second instruction is a store instruction, wherein the firstrecord is a load record, wherein the second record is a store record,and wherein the method further comprises: generating, during anexecution of the multi-threaded program and for the first thread, afirst memory access table including a first plurality of load recordsand further including a first plurality of store records, the firstplurality of load records including the load record; generating, duringthe execution of the multi-threaded program and for the second thread, asecond memory access table including a second plurality of load recordsand further including a second plurality of store records, the secondplurality of store records including the store record; combining thefirst memory access table and the second memory access table; andsorting, based on time of creation, the records of the combined table.15. The system of claim 14, wherein the method further comprises:identifying the load record in the sorted table; and identifying, byscanning through the sorted table relative to the load record, a targetstore record of the second plurality of store records as being a mostrecent store record created prior to the load record that specifies thememory location.
 16. The system of claim 15, wherein the target storerecord is the store record, wherein the store record includes a storevalue of contents of the memory location subsequent to execution of thestore instruction, and wherein the method further comprises: comparing,in response to the identifying the target store record, the load valueto the store value; and determining, in response to the comparing theload value to the store value, that the load value and the store valueare not the same, wherein the comparing the load value to the pre-storevalue occurs in response to the determining that the load value and thestore value are not the same.
 17. A computer program product fordetecting an uninitialized memory reference, the computer programproduct comprising a computer readable storage medium having programinstructions embodied therewith, the program instructions executable bya computer to cause the computer to perform a method comprising:identifying a pre-initialized value of contents of a memory location;identifying a load value of contents loaded from the memory location byexecution of a first instruction that loads from the memory location;comparing the load value to the pre-initialized value; determining,based on the comparing, that the load value and the pre-initializedvalue are the same; and indicating, in response to the determining, thatthe first instruction contains the uninitialized memory reference. 18.The computer program product of claim 17, wherein the identifying thepre-initialized value of contents of the memory location comprises:creating, for a second instruction that stores to the memory location, asecond record that includes a pre-store value of contents of the memorylocation prior to execution of the second instruction, wherein thepre-store value is the pre-initialized value.
 19. The computer programproduct of claim 18, wherein the pre-initialized value is a junk value.20. A computer program product for detecting an uninitialized memoryreference, the computer program product comprising a computer readablestorage medium having program instructions embodied therewith, theprogram instructions executable by a computer to cause the computer toperform a method comprising: identifying a pre-initialized value ofcontents of a memory location, wherein the identifying thepre-initialized value of contents of the memory location comprisescreating, for a second instruction that stores to the memory location, asecond record that includes a pre-store value of contents of the memorylocation prior to execution of the second instruction, and wherein thepre-store value is the pre-initialized value; identifying a load valueof contents loaded from the memory location by execution of a firstinstruction that loads from the memory location, wherein the identifyingthe load value of contents loaded from the memory location by executionof the first instruction that loads from the memory location comprisescreating, for the first instruction, a first record that includes theload value; comparing the load value to the pre-initialized value,wherein the comparing the load value to the pre-initialized valuecomprises comparing the load value from the first record to thepre-store value from the second record; determining, based on thecomparing the load value to the pre-initialized value, that the loadvalue and the pre-initialized value are the same; indicating, inresponse to the determining that the load value and the pre-initializedvalue are the same, that the first instruction contains theuninitialized memory reference, wherein the first instruction is in afirst thread of a multi-threaded program, wherein the second instructionis in a second thread of the multi-threaded program, wherein the firstinstruction is a load instruction, wherein the second instruction is astore instruction, wherein the first record is a load record, andwherein the second record is a store record; generating, during anexecution of the multi-threaded program and for the first thread, afirst memory access table including a first plurality of load recordsand further including a first plurality of store records, the firstplurality of load records including the load record; generating, duringthe execution of the multi-threaded program and for the second thread, asecond memory access table including a second plurality of load recordsand further including a second plurality of store records, the secondplurality of store records including the store record; combining thefirst memory access table and the second memory access table; sorting,based on time of creation, the records of the combined table;identifying the load record in the sorted table; identifying, byscanning through the sorted table relative to the load record, a targetstore record of the second plurality of store records as being a mostrecent store record created prior to the load record that specifies thememory location, wherein the target store record is not the storerecord, wherein the target store record includes a target store value ofcontents of the memory location subsequent to execution of a targetstore instruction and further includes a target pre-store value ofcontents of the memory location prior to execution of the target storeinstruction, wherein the store record includes a store value of contentsof the memory location subsequent to execution of the store instruction;comparing, in response to the identifying the target store record, theload value to the target store value; determining, in response to thecomparing the load value to the target store value, that the load valueand the target store value are not the same; comparing, in response tothe determining that the load value and the target store value are notthe same, the load value to the target pre-store value; determining, inresponse to the comparing the load value to the target pre-store value,that the load value and the target pre-store value are not the same;identifying, by scanning through the sorted table relative to the targetstore record and in response to the determining that the load value andthe target pre-store value are not the same, the store record as being asecond-most recent store record created prior to the load record thatspecifies the memory location; comparing, in response to the identifyingthe store record, the load value to the store value; and determining, inresponse to the comparing the load value to the store value, that theload value and the store value are not the same, wherein the comparingthe load value to the pre-store value occurs in response to thedetermining that the load value and the store value are not the same.